package org.idea.spring.framework.mybatis.utils;

import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;

import java.util.Collections;
import java.util.Map;

/**
 * @Author linhao
 * @Date created in 11:10 下午 2021/6/4
 */
public class EnvironmentUtils {

    private EnvironmentUtils() {
    }

    /**
     * 获取容器内部的一些属性 返回为map的格式
     *
     * @param environment
     * @param keyPrefix
     * @return
     */
    public static Map<String, String> getSubProperties(Environment environment, String keyPrefix) {
        return Binder.get(environment).bind(keyPrefix, Bindable.mapOf(String.class, String.class)).orElseGet(Collections::emptyMap);
    }
}
